package com.zmh.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zmh.entity.BookEntity;
import com.zmh.entity.CatalogEntity;
import com.zmh.entity.Ichange;
import com.zmh.entity.IssueEntity;


/** 
 * 问题信息数据库操作类
 * @author zhoumh
 * @version 创建时间：2018年7月15日 上午10:10:10 
 * @Description 
*/
@Mapper
public interface IssueMapper {
	@Select("SELECT * FROM issue")
//	@Results({
//		@Result(property = "id",  column = "id"),
//		@Result(property = "uuid", column = "uuid"),
//		@Result(property = "name", column = "name"),
//		@Result(property = "count", column = "author"),
//		@Result(property = "description", column = "description")
//	})
	List<IssueEntity> getAll();

	/**
	 * 根据父问题ID获取问题信息
	 * @return: IssueEntity
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:11:42 
	 * @Description:
	 */
	@Select("SELECT * FROM issue WHERE rid = #{rid}")
	IssueEntity getOneByRid(String rid);

	
	/**
	 * 增加问题信息
	 * @return: int
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月25日 下午3:58:32 
	 * @Description:
	 */
	@Insert("INSERT INTO issue(uuid, rid, subject, author, assigned, project, status, tracker, created, updated) VALUES(uuid(), #{rid}, #{subject}, #{author}, #{assigned}, #{project}, #{status}, #{tracker}, #{created}, #{updated})")
	int insert(IssueEntity issue);

	@Update("UPDATE issue SET subject=#{subject}, author=#{author}, assigned=#{assigned}, project=#{project}, status=#{status}, tracker=#{tracker}, created=#{created}, updated=#{updated}, updateTime=#{updateTime} WHERE rid= #{rid}")
	int update(IssueEntity issue);

	@Delete("DELETE FROM issue WHERE uuid =#{uuid}")
	int delete(String uuid);
	/**
	 * 根据问题ID获取问题信息
	 * @return: IssueEntity
	 * @author: zhoumh
	 * @version: 创建时间：2018年7月22日 下午10:11:42 
	 * @Description:
	 */
	@Select("SELECT * FROM ichange WHERE description = #{description} limit 1")
	Ichange getOneBydesc(String description);
	
	@Insert("INSERT INTO ichange(uuid, rid, user, details, context, created, description) VALUES(uuid(), #{rid}, #{user}, #{details}, #{context}, #{created}, #{description})")
	int insertChange(Ichange ichange);
}

